const mysql = require('mysql')
const con = mysql.createPool({
  host: 'localhost',
  user: 'root',
  password: '3051532wyp.',
  database: 's_1712A'
})

// con.query('select * from users where id = ?', [2], (err, data) => {
//   console.log(data, 'data')
//   // con.end()
// })
// let sql = `insert into users (username, password, nickname) values (?, ?, ?)`;
// con.query(sql, ['z', '123', 'zs'], (err, data) => {
//   console.log(data, 'data')
//   // con.end()
// })

// 数据库的i/o操作，异步操作

const exec = (sql, arr) => {
  return new Promise((resolve, reject) => {
    con.query(sql, arr, (err, data) => {
      resolve(data)
    })
  })
}

let sql = `insert into users (username, password, nickname) values (?, ?, ?)`;
exec(sql, ['lisi', 123, 'lisi']).then(res => {
  console.log(res, 'res')
})




